home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / amok98-106 / amok98 / programminginoberon / draft3.mod < prev    next >
Text File  |  1993-10-07  |  2KB  |  77 lines

  1. MODULE Draft;
  2. (* Very tiny graphics editor with  file I/O, Exercise 12.12, page 243. 
  3.     Note: In Programming in Oberon, this module is called Draw. It
  4.     is renamed to avoid naming conflict with the standard Draw package *)
  5.  
  6. IMPORT Display, Viewers, MenuViewers, Oberon, TextFrames, Input, Graphs, Shapes, In, Out;
  7. CONST  right* = 0;  middle* = 1;  left* = 2;
  8.  
  9. PROCEDURE SpanVect(VAR x1, y1, x2, y2: INTEGER);
  10. VAR keys: SET;
  11. BEGIN
  12.     Input.Mouse(keys, x1, y1);
  13.     WHILE left IN keys DO 
  14.         Input.Mouse(keys, x2, y2);  
  15.         Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x2, y2)
  16.     END
  17. END SpanVect;
  18.  
  19. PROCEDURE Modify(F: Graphs.Graph; VAR M: MenuViewers.ModifyMsg);
  20. BEGIN
  21.     IF (M.id = MenuViewers.extend) & (M.dY > 0) THEN
  22.         Display.ReplConst(Display.black, F.X, F.Y + F.H, F.W, M.dY, Display.replace)
  23.     END;
  24.     IF M.Y < F.Y THEN
  25.         Display.ReplConst(Display.black, F.X, M.Y, F.W, F.Y - M.Y, Display.replace)
  26.     END;
  27.     Shapes.SetClipping(F.X, M.Y, F.W, M.H);  
  28.     Graphs.DrawAll(F)
  29. END Modify;
  30.  
  31. PROCEDURE Handle*(F: Display.Frame; VAR M: Display.FrameMsg);
  32. VAR x, y, x1, y1, x2, y2: INTEGER;
  33. BEGIN
  34.     WITH F: Graphs.Graph DO
  35.         IF M IS Oberon.InputMsg THEN
  36.             WITH M: Oberon.InputMsg DO
  37.                 IF M.id = Oberon.track THEN
  38.                     Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, M.X, M.Y);
  39.                     IF left IN M.keys THEN Graphs.NewFigure(F)
  40.                     END
  41.                 END
  42.             END
  43.         ELSIF M IS MenuViewers.ModifyMsg THEN
  44.             Modify(F, M(MenuViewers.ModifyMsg))
  45.         END
  46.     END 
  47. END Handle;
  48.  
  49. PROCEDURE Open*;
  50. CONST span = 0;
  51. VAR 
  52.     g: Graphs.Graph;
  53.     menuF: TextFrames.Frame;  
  54.     V: MenuViewers.Viewer;
  55.     x, y: INTEGER;  name: ARRAY 32 OF CHAR;
  56. BEGIN
  57.     In.Open;  In.Name(name);  
  58.     Oberon.OpenTrack(Display.Left, span);
  59.     menuF := TextFrames.NewMenu(name, "System.Close");
  60.     NEW(g);  g.handle := Handle;  Graphs.Open(name, g); 
  61.     Graphs.spanVect := SpanVect;
  62.     Oberon.AllocateUserViewer(Display.Left, x, y);
  63.     V := MenuViewers.New(menuF, g, TextFrames.menuH, x, y)
  64. END Open;
  65.  
  66. PROCEDURE Store*;
  67. (* Store the marked viewer in file name *)
  68. VAR V: Viewers.Viewer;  name: ARRAY 32 OF CHAR;
  69. BEGIN
  70.     In.Open;  In.Name(name); 
  71.     Out.String("Draft.Store ");  Out.String(name);  Out.Ln;
  72.     V := Oberon.MarkedViewer();
  73.     Graphs.Store(name, V.dsc.next(Graphs.Graph))
  74. END Store;
  75.     
  76.  
  77. END Draft.    (* Copyright M. Reiser, 1992 *)